package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-24
 * Time: 20:49
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");

        int currentSize = bookList.getUsedSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的图书");
        String name = scanner.nextLine();

        for (int i = 0; i < currentSize; i++) {
            //遍历，书架，已初始化的书
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                //看看isBorrowed返回,ture(已借出),还是false(未借出)
                if (book.isBorrowed()) {
                    book.setBorrowed(false);
                    return;
                }
            }
        }
        System.out.println("错误，没有你要归还的图书");
    }
}
